#ifndef __LINUX_COMPAT_H__
#define __LINUX_COMPAT_H__

/* linux_compat.h:
 * linux/windows compatibility
 *
 * (C) Copyright 2013 Ramone de Castillon 
 * ramone.castillon@gmail.com
 * http://poker-botting.blogspot.fr/.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser General Public License
 * (LGPL) version 2.1 which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl-2.1.html
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 */
#ifdef __GNUC__
#define UNUSED(x) UNUSED_ ## x __attribute__((unused))
#else 
# define UNUSED(x) x 
#endif


#ifndef WIN32

# include <stdint.h>

# define HWND uint32_t
# define SOCKET int
# define closesocket close

typedef struct tagRECT { 
   int32_t left;
   int32_t top;
   int32_t right;
   int32_t bottom;
} RECT;

#include <dlfcn.h>
#define DLLHANDLE  void*

#else /* WIN32 */

#include <windows.h>
# define INET_ADDRSTRLEN 16

#define snprintf _snprintf

static inline char* strerror2() {
	static char message[1024];
	FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, message, sizeof(message) / sizeof(char), NULL);
	return message;
}

//#define UNUSED UNREFERENCED_PARAMETER
#define DLLHANDLE HINSTANCE

#define RTLD_LAZY 0
#define RTLD_NOW  0
static inline DLLHANDLE dlopen(const char *dllname, int UNUSED(ignore))
{
	return LoadLibrary(dllname);
}

#define dlclose FreeLibrary
#define dlerror strerror2
#define dlsym   GetProcAddress

#endif /* WIN32 */

#define _STRIFY_1(x...) #x
#define _STRIFY(x...) _STRIFY_1(x)


#endif /* __LINUX_COMPAT_H__ */
